package main

import (
	"github.com/antonmedv/expr"
	"log"
)

func Pexpr(c int) {
	params := createParams()

	program, err := expr.Compile(example, expr.Env(params))
	if err != nil {
		log.Fatal(err)
	}

	var out interface{}

	for n := 0; n < c; n++ {
		out, err = expr.Run(program, params)
	}

	if err != nil {
		log.Fatal(err)
	}
	if !out.(bool) {
		log.Println("result error")
	}
}

func Pexpr_startswith(c int) {
	params := map[string]interface{}{
		"name":  "/groups/foo/bar",
		"group": "foo",
	}

	program, err := expr.Compile(`name startsWith "/groups/" + group`, expr.Env(params))
	if err != nil {
		log.Fatal(err)
	}

	var out interface{}

	for n := 0; n < c; n++ {
		out, err = expr.Run(program, params)
	}

	if err != nil {
		log.Fatal(err)
	}
	if !out.(bool) {
		log.Println("result error")
	}
}
